package com.cib.icarus.desensitize.wrapper.internals;

import com.alibaba.fastjson.JSON;
import com.cib.icarus.core.utils.ClassUtils;
import com.cib.icarus.desensitize.wrapper.DesAbstractWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FastjsonDesWrapper extends DesAbstractWrapper {

    private static final Logger logger = LoggerFactory.getLogger(FastjsonDesWrapper.class);
    private static final FastjsonDesWrapper instance = new FastjsonDesWrapper();


    public static FastjsonDesWrapper getInstance() {
        return instance;
    }

    private FastjsonDesWrapper() {
    }

    @Override
    public String showAsString(Object object) {
        try {
            return JSON.toJSONString(desensitize(object));
        } catch (Exception e) {
            logger.warn("try to write {}  desensitize json occur error {}!!!, will return toString", object, e.getMessage(), e);
            return object.toString();
        }
    }

    @Override
    public Object deepCopy(Object object) {
        return JSON.parseObject(JSON.toJSONString(object), object.getClass());
    }

}
